package com.ics.atable.chat.model.dto;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 指标查询关键词提取结果实体类
 *
 * @author haohongbin
 */
@Slf4j
@Data
@AllArgsConstructor
@Schema(description = "指标查询关键词提取结果实体类")
public class KeyWordExtract {

    @Schema(description = "原始统计项")
    private List<String> items;

    @Schema(description = "加入同义词的统计项")
    private List<List<String>> itemsWithSynonyms;

    @Schema(description = "统计指标")
    private List<String> indicators;

    @Schema(description = "时间")
    private List<String> time;

    @Schema(description = "完整地址")
    private String address;

    @Schema(description = "省级")
    private String province = "贵州省";

    @Schema(description = "市级")
    private String city;

    @Schema(description = "县级")
    private String county;

    @Schema(description = "镇级")
    private String town;

    @Schema(description = "村级")
    private String village;

    public KeyWordExtract() {
    }

    public KeyWordExtract(List<String> items, List<String> indicators, String address) {
        this.items = items;
        this.indicators = indicators;
        this.address = address;
    }

    @JsonCreator
    public static KeyWordExtract fromJsonString(String json) {
        try {
            log.info("json: {}", json);
            ObjectMapper mapper = new ObjectMapper();
            return mapper.readValue(json, KeyWordExtract.class);
        } catch (Exception e) {
            throw new IllegalArgumentException("Failed to parse JSON: " + json, e);
        }
    }
}
